package com.ruoyi.web.controller.tourism;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Carousel;
import com.ruoyi.system.service.ICarouselService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 轮播图Controller
 *
 * @author Y.C
 * @date 2024-02-21
 */
@Api(tags = "轮播图")
@RestController
@RequestMapping("/system/carousel")
public class CarouselController extends BaseController
{
    @Autowired
    private ICarouselService carouselService;

    /**
     * 查询轮播图列表
     */
    @ApiOperation("查询轮播图列表")
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(Carousel carousel)
    {
        startPage();
        List<Carousel> list = carouselService.selectCarouselList(carousel);
        return getDataTable(list);
    }

    /**
     * 导出轮播图列表
     */
    @ApiOperation("导出轮播图列表")
    @Anonymous
    @PostMapping("/export")
    public void export(HttpServletResponse response, Carousel carousel)
    {
        List<Carousel> list = carouselService.selectCarouselList(carousel);
        ExcelUtil<Carousel> util = new ExcelUtil<Carousel>(Carousel.class);
        util.exportExcel(response, list, "轮播图数据");
    }

    /**
     * 获取轮播图详细信息
     */
    @Anonymous
    @ApiOperation("获取轮播图详细信息")
    @GetMapping(value = "/{carouselId}")
    public AjaxResult getInfo(@PathVariable("carouselId") Long carouselId)
    {
        return success(carouselService.selectCarouselByCarouselId(carouselId));
    }

    /**
     * 新增轮播图
     */
    @Anonymous
    @PostMapping
    @ApiOperation("新增轮播图")
    public AjaxResult add(@RequestBody Carousel carousel)
    {
        boolean save = carouselService.save(carousel);
        if (save) {
            return success();
        }else {
            return error();
        }
    }

    /**
     * 修改轮播图
     */
    @Anonymous
    @PutMapping
    @ApiOperation("修改轮播图")
    public AjaxResult edit(@RequestBody Carousel carousel)
    {
        return toAjax( carouselService.updateById(carousel));
    }

    /**
     * 删除轮播图
     */
    @ApiOperation("删除轮播图")
    @Anonymous
	@DeleteMapping("/{carouselIds}")
    public AjaxResult remove(@PathVariable Long[] carouselIds)
    {
        return toAjax(carouselService.removeByIds(Arrays.asList(carouselIds)));
    }
}
